/*	kd:
	
	I swear this has become popular enough in the status bar that I should just
	make this a struct.
	
	There are certain items that trigger certain behaviour when you equip or
	unequip them. We could trigger those from the inventories themselves, but I
	don't wanna burden that code some more (given we can't even communicate with
	the status bar from anywhere else except by doing the same thing in green).
	
	So what we do is check whether we just acquired or dropped the item.
	
	*/

struct Gc_WeapObserver {
	private class <Weapon> weap_class;
	bool is_selected;
	bool old_is_selected;
	
	void Observe (class <Weapon> to_observe) {
		weap_class = to_observe;
		is_selected = false;
		old_is_selected = false;
	}
	
	void Next (PlayerInfo player) {
		old_is_selected = is_selected;
		is_selected = player.ReadyWeapon is weap_class;
	}
	
	bool Selected () const {
		return is_selected && !old_is_selected;
	}
	
	bool Holding () const {
		return is_selected;
	}
	
	bool Deselected () const {
		return !is_selected && old_is_selected;
	}
}

struct Gc_InvObserver {
	private class <Inventory> inv_class;
	private int counter;
	private int old_counter;
	private int max_amount;
	
	void Observe (class <Inventory> to_observe) {
		inv_class = to_observe;
		counter = 0;
		old_counter = 0;
	}
	
	void Next (Actor mo) {
		let mo_inv	= mo.FindInventory(inv_class);
		old_counter	= counter;
		counter		= mo.CountInv(inv_class);
		
		if(mo_inv) {
			max_amount	= mo_inv.maxamount;
		}
		
		else {
			max_amount	= 0;
		}
	}
	
	int Count () const {
		return counter;
	}
	
	bool Has () const {
		return 0 < counter;
	}
	
	bool Refilled () const {
		return max_amount <= counter && old_counter < max_amount;
	}
	
	bool StartedUsing () const {
		return counter < max_amount && max_amount <= old_counter;
	}
	
	bool UsedUp () const {
		return counter <= 0 && 0 < old_counter;
	}
	
	bool Dropped () const {
		return counter < old_counter;
	}
	
	bool Raised () const {
		return old_counter < counter;
	}
	
	bool DroppedBelow (int amount) const {
		return counter < amount && amount <= old_counter;
	}
	
	bool RaisedAbove (int amount) const {
		return amount <= counter && old_counter < amount;
	}
	
	bool Got () const {
		return 0 < counter && old_counter < 1;
	}
	
	bool Lost () const {
		return 0 < old_counter && counter < 1;
	}
}
